package com.lhb.aicodemother.ai.core.saver;

import com.lhb.aicodemother.ai.model.HtmlCodeResult;
import com.lhb.aicodemother.ai.model.MultiFileCodeResult;
import com.lhb.aicodemother.ai.model.enums.CodeGenTypeEnum;
import com.lhb.aicodemother.exception.BusinessException;
import com.lhb.aicodemother.exception.ErrorCode;

import java.io.File;

/*
* 代码文件保存执行器
* */
public class CodeFileSaverExecutor {
    private final static HtmlCodeFileSaverTemplate htmlCodeFileSaverTemplate = new HtmlCodeFileSaverTemplate();
    private final static MultiFileCodeFileSaverTemplate multiFileCodeFileSaverTemplate = new MultiFileCodeFileSaverTemplate();

    public static File executeSaver(Object codeResult, CodeGenTypeEnum codeGenTypeEnum,Long appId){
        return switch (codeGenTypeEnum){
            case HTML -> htmlCodeFileSaverTemplate.saveCode((HtmlCodeResult) codeResult,appId);
            case MULTI_FILE -> multiFileCodeFileSaverTemplate.saveCode((MultiFileCodeResult) codeResult,appId);
            default -> throw new BusinessException(ErrorCode.SYSTEM_ERROR,"不支持的生成类型：" + codeGenTypeEnum);
        };
    }
}
